/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * WordDocument.java
 *
 * Created on 10/12/2012, 03:43:53
 */

package IU;

/**
 *
 * @author puflitos
 */
import java.io.File;
 import java.awt.event.*;
 import javax.swing.*;
 import java.awt.*;

 public class WordDocument extends JFrame {
 private JButton btnOpen;
 private JLabel jLabel1;
   private JTextField txtDocNumber;

     private static String DIR ="c:\\PROYECTO.doc"; // folder where word documents are present.
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
   @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

 public WordDocument() {
       super("Manual de Ayuda al Usuario");
    initComponents();
    }

 private void initComponents1() {
       jLabel1 = new JLabel();
       txtDocNumber = new JTextField();
      btnOpen = new JButton();

       Container c = getContentPane();
        c.setLayout(new java.awt.FlowLayout());
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

      jLabel1.setText("Enter Document Number : ");
  c.add(jLabel1);
 txtDocNumber.setColumns(5);
    c.add(txtDocNumber);

       btnOpen.setText("Open Document");
        btnOpen.addActionListener(new ActionListener() { // anonymous inner class
            public void actionPerformed(ActionEvent evt) {
     Desktop desktop = Desktop.getDesktop();
	       try {
	            File f = new File( DIR + txtDocNumber.getText() + ".doc");
	            desktop.open(f); // opens application (MSWord) associated with .doc file
	          }
	     catch(Exception ex) {

	            JOptionPane.showMessageDialog (WordDocument.this, ex.getMessage (), "Error", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(WordDocument.this,ex.getMessage(),"Error", JOptionPane.ERROR_MESSAGE);
	          }
            }
        });

         c.add(btnOpen);

    } // initCompnents()


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
 //   @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
   
    /**
    * @param args the command line arguments
    */
   public static void main(String args[]) {
         WordDocument wd = new WordDocument();
         wd.setSize(300,100);
         wd.setVisible(true);
    }




    // Variables declaration - do not modify
    // End of variables declaration




    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

}
